// @ts-nocheck
import { CharStream, CommonTokenStream, ParseTreeWalker } from 'antlr4ng';
import type { ParserRuleContext, ParseTreeListener } from 'antlr4ng';

import { ExprLexer } from '~generated/ExprLexer.ts';
import { ExprParser } from '~generated/ExprParser.ts';
import { ExprListener } from '~generated/ExprListener.ts';

class MyExprListener extends ExprListener {
  enterEveryRule(ctx: ParserRuleContext) {
    console.log('Entering rule: ' + ctx.getText());
  }
  exitEveryRule(ctx: ParserRuleContext) {
    console.log('Exiting rule: ' + ctx.getText());
  }
}

const input = 'a = 3 + 5\nb = a * 2\n';
const inputStream = CharStream.fromString(input);
const lexer = new ExprLexer(inputStream);
const tokenStream = new CommonTokenStream(lexer);
const parser = new ExprParser(tokenStream);

const tree = parser.prog();

const listener = new MyExprListener();
ParseTreeWalker.DEFAULT.walk(listener, tree);
